const net = require("net");
const tcppkg = require("../netbus/tcppkg");
const proto_man = require("../netbus/proto_manager");

var sock = net.connect({
    port: 6081,
    host: "127.0.0.1",
}, function () {
    console.log('connected to server!');
});

var data = {
    uname: "jackie3300",
    upwd: "123456",
};

sock.on("connect", function () {
    console.log("connect success");

    // stype:1, ctype:2, body:"hello jackie330"
    var cmd_buf = proto_man.encode_cmd(proto_man.PROTO_BUF, 1, 1, data);
    // 将编码好的数据打成二进制包
    var cmd_buf = tcppkg.package_data(cmd_buf);
    sock.write(cmd_buf);
});



sock.on("error", function (e) {
    console.log("error", e);
});


sock.on("close", function () {
    console.log("close");
});


sock.on("end", function () {
    console.log("end event");
});

sock.on("data", function (data) {
    console.log(data.toString());
});